package com.supcalls.config;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ZookeeperConfig {

    private static final String ZK_CONNECT_STRING = "127.0.0.1:2181"; // ZooKeeper 地址
    private static final int SESSION_TIMEOUT_MS = 5000;
    private static final int CONNECTION_TIMEOUT_MS = 3000;

    @Bean
    public CuratorFramework curatorFramework() {
        CuratorFramework client = CuratorFrameworkFactory.newClient(
                ZK_CONNECT_STRING,
                SESSION_TIMEOUT_MS,
                CONNECTION_TIMEOUT_MS,
                new ExponentialBackoffRetry(1000, 3)
        );
        client.start();
        return client;
    }
}
